KISSY.use("node",function(S,Node){ 
	var $=Node.all;
	var contdown={};
	var gift={};
	var mywin={};
	var gg={};
	var win={};
	var action={};
	var cart={};
	$(".js-animon").on("click",function(){
		saveanimcfg(1);
	});
	$(".js-animoff").on("click",function(){
		saveanimcfg(0);
	});
	function saveanimcfg(status){
		KISSY.io({
			url: "/?a=anmicfg_save&m=shopmanage&c=frontcfg",
			data: {"status":status},
			success: function(data, textStatus) {
				if(data.status==1){
					if(data.anmicfg==1){
						$(".js-animon").addClass("button-danger");
						$(".js-animoff").removeClass("button-danger");
					}else{
						$(".js-animoff").addClass("button-danger");
						$(".js-animon").removeClass("button-danger");
					}
				}else{
					showDialog("配置失败","请确认您已经配置活动。","form-horizontal");
				}
			},
			complete: function(data){
			},
			error: function(){
				alert('error');
			},
			dataType:"jsonp"
		});
	}
	$(".helper").on("click",function(){
		showDialog("帮助",$(this).attr("data-tip"),"form-horizontal");
		$(".helper-in").on("click",function(){
			closeDialog();
			showDialog("帮助",$(this).attr("data-tip"),"form-horizontal");
		});
	});
	$(".form").on("change",function(){
		dojson();
	});
	$(".js-wgsubmit").on("click",function(){
		var t1=$("input").getDOMNodes();
		for(var i=0;i<t1.length;i++)
		   {
			   if(t1[i].type == "checkbox")
			   {
				   if(!(t1[i].checked))
				   {
					   t1[i].checked = true;
					   t1[i].value = "0";
				   }
			   }
		   }
		$(".form1").fire("submit");
	});
	function dojson(){
		contdown.left = $(".contdown-left").val()+"px";
		contdown.top = $(".contdown-top").val()+"px";
		contdown.visibility = $(".contdown-hide").getDOMNode().checked?"hidden":"visible";
		
		gift.right = $(".gift-right").val()+"px";
		gift.top = $(".gift-top").val()+"px";
		gift.visibility = $(".gift-hide").getDOMNode().checked?"hidden":"visible";

		mywin.right = $(".mywin-right").val()+"px";
		mywin.top = $(".mywin-top").val()+"px";
		mywin.visibility = $(".mywin-hide").getDOMNode().checked?"hidden":"visible";

		gg.right = $(".gg-right").val()+"px";
		gg.top = $(".gg-top").val()+"px";
		gg.visibility = $(".gg-hide").getDOMNode().checked?"hidden":"visible";

		win.right = $(".win-right").val()+"px";
		win.bottom = $(".win-bottom").val()+"px";
		win.visibility = $(".win-hide").getDOMNode().checked?"hidden":"visible";

		action.left = $(".action-left").val()+"px";
		action.top = $(".action-top").val()+"px";
		action.width = $(".action-width").val()+"px";
		action.height = $(".action-height").val()+"px";
		action.background = "url("+$(".action-pic").val()+") no-repeat";

		cart.left = $(".cart-left").val()+"px";
		cart.top = $(".cart-top").val()+"px";
		cart.width = $(".cart-width").val()+"px";
		cart.height = $(".cart-height").val()+"px";
		cart.background = "url("+$(".cart-pic").val()+") no-repeat";
		var code = {"contdown":contdown,"gift":gift,"mywin":mywin,"gg":gg,"win":win,"action":action,"cart":cart};
		$(".js-code").val(KISSY.JSON.stringify(code));
	}
	if($(".js-code").getDOMNode()){
	dojson();
	}
	$(".js-readdefault").on("click",function(){
		$(".contdown-left").val($(".contdown-left").attr("data-default"));
		$(".contdown-top").val($(".contdown-top").attr("data-default"));
		$(".contdown-hide").getDOMNode().checked=false;
				
		$(".gift-right").val(60);
		$(".gift-top").val(80);
		$(".gift-hide").getDOMNode().checked=false;

		$(".mywin-right").val(20);
		$(".mywin-top").val(160);
		$(".mywin-hide").getDOMNode().checked=false;

		$(".gg-right").val(120);
		$(".gg-top").val(158);
		$(".gg-hide").getDOMNode().checked=false;

		$(".win-right").val(40);
		$(".win-bottom").val(54);
		$(".win-hide").getDOMNode().checked=false;

		$(".action-left").val($(".action-left").attr("data-default"));
		$(".action-top").val($(".action-top").attr("data-default"));
		$(".action-width").val($(".action-width").attr("data-default"));
		$(".action-height").val($(".action-height").attr("data-default"));
		var pic = $(".action-pic").attr("data-default");
		$(".action-pic").val(pic);
		$(".upImage1").empty();
		$("<img src=\""+pic+"\" />").appendTo(".upImage1");
		
		$(".cart-left").val(60);
		$(".cart-top").val(260);
		$(".cart-width").val(160);
		$(".cart-height").val(37);
		$(".cart-pic").val("http://img04.taobaocdn.com/imgextra/i4/27390555/TB26FHAbpXXXXamXpXXXXXXXXXX-27390555.png");
		$(".upImage3").empty();
		$("<img src=\"http://img04.taobaocdn.com/imgextra/i4/27390555/TB26FHAbpXXXXamXpXXXXXXXXXX-27390555.png\" />").appendTo(".upImage3");
		
		dojson();
	});
});